package com.chenfeng.ego.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.chenfeng.ego.commons.pojo.EasyUIDataGrid;
import com.chenfeng.ego.commons.util.IDUtils;
import com.chenfeng.ego.mapper.MyTbCatParam;
import com.chenfeng.ego.mapper.TbItemParamMapper;
import com.chenfeng.ego.pojo.MyTbCatParams;
import com.chenfeng.ego.pojo.TbItemParam;
import com.chenfeng.ego.pojo.TbItemParamExample;
import com.chenfeng.ego.service.TbItemParamService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
//参数的service类
@Service
public class TbitemParamServiceImpl implements TbItemParamService
{
	@Resource
	TbItemParamMapper tbItemParamMapper;
	@Resource
	MyTbCatParam myTbCatParam;
	@Override
	//显示商品类别
	public EasyUIDataGrid selCatParam(int page,int rows)
	{
		PageHelper helf = new PageHelper();
		helf.startPage(page, rows);
		List<MyTbCatParams> param = myTbCatParam.selTbCatParam();
		PageInfo<MyTbCatParams> pageinfo = new PageInfo<>(param);
		EasyUIDataGrid uiData = new EasyUIDataGrid();
		uiData.setRows(pageinfo.getList());
		uiData.setTotal(pageinfo.getTotal());
		return uiData;
	}
	@Override
	//查找分类中是否已经存在该类别的类
	public int selParamCat(Long id)
	{
		TbItemParamExample example = new TbItemParamExample();
		example.createCriteria().andIdEqualTo(id);		
		int result = this.tbItemParamMapper.countByExample(example);
		return result;
	}
	//插入参数
	@Override
	public int insertParent(TbItemParam itemParam, Long id) throws Exception
	{
		itemParam.setCreated(new Date());
		itemParam.setItemCatId(id);
		itemParam.setId(IDUtils.genItemId());
		itemParam.setUpdated(new Date());	
		return tbItemParamMapper.insert(itemParam);
	}
	//展示商品参数
	@Override
	public TbItemParam showTbitemParam(Long id)
	{
		TbItemParamExample example = new TbItemParamExample();
		example.createCriteria().andItemCatIdEqualTo(id);
		List<TbItemParam> tb = this.tbItemParamMapper.selectByExampleWithBLOBs(example);
		System.out.println("我是tb"+tb);
		if(tb!=null&&tb.size()>0)
		{
			
			return tb.get(0);
		}
		return null;
	}
	//删除通过id
	public int deleteByIds(List<Long> ids)throws Exception
	{
		TbItemParamExample temple = new TbItemParamExample();
		temple.createCriteria().andIdIn(ids);
		this.tbItemParamMapper.deleteByExample(temple);
		return this.tbItemParamMapper.deleteByExample(temple);
	}
	

}
